package org.votes.dao.impl;

import java.util.List;

import javax.persistence.Entity;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.votes.bean.Manager;
import org.votes.dao.ManagerDao;

@Entity
@Repository("managerDao")
public class ManagerDaoImpl implements ManagerDao {
	
	@Autowired
	private SessionFactory sessionFactory;

	
	public Session getSession() {
		return sessionFactory.getCurrentSession();
	}
	
	@Override
	public boolean find(Manager manager) {
		String sql = "select * from manager where name = '" +manager.getName()+ "' and password = '" +manager.getPassword()+ "'";
		Query query = getSession().createSQLQuery(sql);
			List<Manager> list = query.list();
			if(list.size() > 0) 
				return true;
		return false;
	}

	@Override
	public void save(Manager manager) {
		getSession().save(manager);
	}

	@Override
	public List<Manager> findAll() {
		Query query = getSession().createQuery("from Manager");
		return query.list();
	}

}
